home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Sample Code / Graphics Samples / Patterned Curve ƒ / patterned curve.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-14  |  4.6 KB  |  153 lines  |  [TEXT/KAHL]

  1. /*
  2.     patterned curve.c
  3.     
  4.     This file contains the calls to create a "thick" curve and fill it will a "star" as the pattern.
  5.         
  6.     NOTES:
  7.     • This file requires the new "GX"-ified interface files and libraries. With the interface files, all types and function
  8.     names are proceeded by a "gx" for types or "GX" for function names.
  9.     
  10.     • This file requires the following files to run correctly:
  11.         "graphics shell.c", "graphics debug library.c", "transform library.c".
  12.         
  13.     • This file prints the "best" in landscape mode.
  14.     
  15.     ©1992 - 1993  Apple Computer, Inc.
  16.     All rights reserved.
  17. */
  18.  
  19. #include <events.h>
  20. #include <windows.h>
  21.  
  22. #include "font library.h"
  23. #include "graphics debugging.h"
  24. #include "graphics libraries.h"
  25. #include "graphics toolbox.h"
  26. #include "graphics shell.h"
  27.  
  28. //
  29. //  Set up the title and size of the window 
  30. //
  31. Str255     gWindowTitle = "\p Patterned Curve";
  32. Rect         gWindowQDRect  = {50, 20, 235, 375};
  33.  
  34. //
  35. //    If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  36. //    the "debugging" version of the Secret Graphics init.  If this version of the init is not installed, nothing bad will happen, 
  37. //    but these  functions will not work. The "debugging" version of the Secret  Graphics init is approximately 700K.
  38. //
  39. boolean    gDebugging = true;
  40.  
  41. //
  42. //     Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  
  43. //
  44. boolean    gGiveMeValidation = true;
  45.  
  46.  
  47. //
  48. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the NewGraphicsClient routine
  49. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  50. //    With  gGraphicsHeapSize set to 25k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  51. //
  52. long        gGraphicsHeapSize = 25;
  53.  
  54. gxShape     gShape;
  55.  
  56. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  57.  
  58. void DoInitialization(gWindow)
  59. WindowPtr gWindow;
  60. {
  61.     gxCurve             curveGeometry = {ff(25), ff(125), ff(100), 0, ff(225), ff(125)};    
  62.     gxShape            starShape, testRect;
  63.     gxRectangle        starShapeBounds;
  64.     gxPatternRecord    starPattern;
  65.     
  66.     long starGeometry[] = {1, //  number of contours
  67.                         5, //  number of points 
  68.                           ff(60), 0, ff(90), ff(90),  ff(0), ff(30),  ff(120), ff(30), ff(0), ff(90)};   //  the points
  69.      
  70.      InitCommonColors();
  71.  
  72.     gShape = GXNewCurve (&curveGeometry);
  73.     
  74.     //
  75.     // Create a star gxShape which will be used as the fill pattern
  76.     //
  77.     starShape =  GXNewPolygons((gxPolygons *) starGeometry);
  78.      GXScaleShape(starShape, fl(0.25), fl(0.25), 0, 0);
  79.  
  80.     //
  81.     //    Get the bounds of our star gxShape.  We use the bounds to setup the u and v vectors of the pattern 
  82.     //    record. We want "gShape" to be filled  with the star where each star is placed at edge of the
  83.     //    previous star (i.e so the pattern's do not overlap).
  84.     //    
  85.      GXGetShapeBounds(starShape, 0L, &starShapeBounds);
  86.  
  87.     starPattern.u.x = 0;
  88.     starPattern.u.y = starShapeBounds.bottom;
  89.      starPattern.v.x = starShapeBounds.right + fixed1;
  90.     starPattern.v.y = 0;
  91.  
  92.     starPattern.attributes = gxPortAlignPattern;
  93.     starPattern.pattern = starShape;
  94.  
  95.     GXSetShapePattern(gShape, &starPattern);
  96.     
  97.     //
  98.     //    We can dispose of our star gxShape because it is now referenced from within the
  99.     //    pattern record contained in "gShape".
  100.     //
  101.      GXDisposeShape (starShape);
  102.     
  103.     SetShapeCommonColor (gShape, blue);
  104.     GXSetShapePen (gShape, ff(75));
  105.     GXMoveShape (gShape,  ff(50), 0);
  106. }
  107.  
  108. /*------ DoClick ---------------------------------------------------------------------------------------*/
  109.  
  110. void DoClick(gWindow)
  111. WindowPtr gWindow;
  112. {
  113. }
  114.  
  115.  
  116.  
  117.  
  118. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  119.  
  120. void DoDraw(gWindow)
  121. WindowPtr gWindow;
  122. {
  123.     GXDrawShape (gShape);
  124. }
  125.  
  126.  
  127. /*------ DoDispose -------------------------------------------------------------------------------------*/
  128.  
  129. void DoDispose(gWindow)
  130. WindowPtr gWindow;
  131. {
  132.     /**  
  133.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  134.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  135.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  136.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  137.         can turn notices on in this file by setting gDebugging = TRUE (above).
  138.     **/
  139.     GXDisposeShape(gShape);  
  140.      GXDisposeShape(gWindowBoundsShape);  
  141.        DisposeCommonColors();
  142.        DisposeWindow(gWindow);
  143. }
  144.     
  145.  
  146.  
  147. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  148.  
  149. void DoIdle(gWindow)
  150. WindowPtr gWindow;
  151. {
  152. }
  153.